package com.sgb.kjwl.view.ui.adapter.manage;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemJingYingGaodeSearchBinding;
import com.sgb.kjwl.model.LocationAddressInfo;

import java.util.ArrayList;

/**
 * 企业经营 我的位置 搜索关键字列表
 */
public class JingYingGaodeSearchAdapter extends RecyclerView.Adapter<JingYingGaodeSearchAdapter.ViewHolder> {
    private Context context;
    private ArrayList<LocationAddressInfo> datas;
    private final LayoutInflater inflater;
    private Callback callback;


    public void setCallback(Callback callback) {
        this.callback = callback;
    }


    public JingYingGaodeSearchAdapter(Context context, ArrayList<LocationAddressInfo> list) {
        this.context = context;
        datas = list;
        inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemJingYingGaodeSearchBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_jing_ying_gaode_search, parent, false);
        return new ViewHolder(binding);
    }


    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        LocationAddressInfo data = datas.get(position);
        holder.getBinding().name.setText(data.getTitle());
        holder.getBinding().tvDetail.setText(data.getText());
        holder.itemView.setOnClickListener(v -> callback.back(data));
        holder.getBinding().executePendingBindings();
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private ItemJingYingGaodeSearchBinding mBinding;

        public ItemJingYingGaodeSearchBinding getBinding() {
            return mBinding;
        }

        public ViewHolder(ItemJingYingGaodeSearchBinding binding) {
            super(binding.getRoot());
            mBinding = binding;
        }
    }

    public interface Callback {
        void back(LocationAddressInfo bean);

    }

}